'use strict';

const { Controller } = require('ee-core');
const Log = require('ee-core/log');
const Services = require('ee-core/services');
const { success, error } = require('../common');
/**
 * example
 * @class
 */
class NetTCPController extends Controller {

  constructor(ctx) {
    super(ctx);
    this.service = Services.get('netTCP');
  }


  /**
   * 所有方法接收两个参数
   * @param args 前端传的参数
   * @param event - ipc通信时才有值。详情见：控制器文档
   */

  async connect (args) {
    try {
      let res = await this.service.connect(args);
      return success(res);      
    } catch (e) {
      return error(e.message);
    }
  }
  async send (args) {
    try {
      let res = await this.service.send(args);
      return success(res);      
    } catch (e) {
      return error(e.message);
    }
  }

  async read (args) {
    try {
      let res = await this.service.read(args);
      return success(res);      
    } catch (e) {
      return error(e.message);
    }
  }

  async close () {
    try {
      let res = await this.service.close();
      return success(res);      
    } catch (e) {
      return error(e.message);
    }
  }

  
}

NetTCPController.toString = () => '[class NetTCPController]';
module.exports = NetTCPController;  